package com.haiheng.module_main.mode

import com.google.gson.Gson
import com.haiheng.common.api.API
import com.haiheng.common.bean.*
import com.haiheng.common.bean.req.LoginReq
import com.haiheng.common.constant.AppConstant
import com.haiheng.library_base.utils.ApplicationUtils
import com.haiheng.library_base.utils.NetworkUtils
import com.haiheng.module_main.bean.req.AccessTokenReq
import com.haiheng.module_main.bean.req.QueryBookReq

/**
 *
 * @Des:
 * @Author: hwz
 * @Date:2022/5/6 0006
 * @Version: 1.0
 */
 object RequestDataHelper {
    fun getAddMachineData() :BaseReqVo<AddMachineReq> {
        var req =BaseReqVo<AddMachineReq>()
        var machineReq = AddMachineReq()
        machineReq.LibraryCode = AppConstant.getLibraryCode()
        machineReq.MachineUuid = AppConstant.getMachineUuid()
        machineReq.Name = AppConstant.getMachineName()
        machineReq.Address = ""
        machineReq.MachineCatalogType = AppConstant.getMachineCatalogType()
        machineReq.MachineModelType = AppConstant.getMachineModelType()
        req.data = machineReq
        req.appInfo = ReqAppInfoVo()
        req.operation = API.OPERATION.ADDMACHINE
        req.requestObject = API.PARAM.PARAGM_REQUEST_OBJECT
        req.description = "添加广告屏设备"
        return req
    }


    fun getAddStatusData():BaseReqVo<AddStatusReq>{

        //LibraryCode MachineUuid MachineCatalogType MachineModelType必传
        //Name
        var req =BaseReqVo<AddStatusReq>()
        var addStatusReq = AddStatusReq()
        addStatusReq.MachineUuid = AppConstant.getMachineUuid()
//        addStatusReq.Name = AppConstant.getMachineName()
//        addStatusReq.MachineCatalogType = API.PARAM.PARAGE_CATALOG_TYPE
//        addStatusReq.MachineModelType = API.PARAM.PARAGN_MODE_TYPE
//        addStatusReq.LibraryCode = AppConstant.getLibraryCode()

        addStatusReq.ComponentType = 0
        addStatusReq.Ok = true.toString()
        var content = AddStatusContent()
        content.AppRunStatus = 0 // //应用运行状态 0（正常）、1（闲置没人操作）、2（有人操作中）、3（故障）
        content.MqttDevClientStatus = false
        content.OuterNetStatus = NetworkUtils.isNetworkAvailable(ApplicationUtils.application)
        content.InnerNetStatus = true
        content.NanoClientStatus = true//

        var extDevicesRunStatus  = ExtDevicesRunStatus()

        var hfReader: DevicesRunStatusData = DevicesRunStatusData()//阅读器
        hfReader.DisplayName = "荣睿阅读器"
        setDevRunStatus(hfReader,AppConstant.getRfidReaderRunStatus())
        var sanDev: DevicesRunStatusData = DevicesRunStatusData()//扫码
        sanDev.DisplayName = "扫码器"
        setDevRunStatus(sanDev,AppConstant.getScanDevRunStatus())
        var cameraDev: DevicesRunStatusData = DevicesRunStatusData()//摄像头-人脸
        cameraDev.DisplayName = "摄像头"
        setDevRunStatus(cameraDev,AppConstant.getCameraDevRunStatus())
        var radarDetectionDev: DevicesRunStatusData = DevicesRunStatusData()//雷达
        radarDetectionDev.DisplayName = "雷达"
        setDevRunStatus(radarDetectionDev,AppConstant.getRadarDetectionRunStatus())
        var micNoiseReduction: DevicesRunStatusData = DevicesRunStatusData()//降噪
        micNoiseReduction.DisplayName = "降噪阵列"

        setDevRunStatus(micNoiseReduction,AppConstant.getMicNoiseDevRunStatus())
        extDevicesRunStatus.HfReader = hfReader
        extDevicesRunStatus.ScanDev = sanDev
        extDevicesRunStatus.CameraDev = cameraDev
        extDevicesRunStatus.RadarDetectionDev = radarDetectionDev
        extDevicesRunStatus.MicNoiseReduction = micNoiseReduction
        content.ExtDevicesRunStatus = extDevicesRunStatus
        addStatusReq.Content = content

        req.data = addStatusReq
        req.appInfo = ReqAppInfoVo()
        req.operation = API.OPERATION.ADDSTATUS
        req.requestObject = API.PARAM.PARAGM_REQUEST_OBJECT
        req.description = "上报设备状态"
        return req
    }

    fun setDevRunStatus(dev: DevicesRunStatusData, status: Int) {
        when(status){
            AppConstant.DEV_RUN_STATUS.FAULT->{
                dev.IsWorking = false
                dev.IsInitial = false
                dev.IsOpend = false
                dev.IsOnline = false
                dev.IsSendNotification = false
            }

            AppConstant.DEV_RUN_STATUS.ONLINE ->{
                dev.IsWorking = true
                dev.IsInitial = true
                dev.IsOpend = true
                dev.IsOnline = true
                dev.IsSendNotification = false
            }
        }
    }
    fun getLoginReqDataByPatronsnAndPassword(patronsn:String,password:String): BaseReqVo<LoginReq>{
        var logreq = BaseReqVo<LoginReq>()
        var appInfo = ReqAppInfoVo()
        logreq.appInfo = appInfo
        logreq.description = ""
        logreq.operation = API.OPERATION.QUERYPATRONINFOBYPATRONSN
        logreq.requestObject = API.PARAM.PARAGM_ACS_REQUEST_OBJECT
        var login = LoginReq()
        login.patronsn  = patronsn
        login.libraryCode = AppConstant.getLibraryCode()
        login.mac = AppConstant.getMachineUuid()
        login.password =if (AppConstant.isPatronPasswordValid()) password else ""
        logreq.data = login
        return logreq
    }
    fun getQueryBookInfoData(bookSn: String):BaseReqVo<QueryBookReq>{
        var baseReqVo = BaseReqVo<QueryBookReq>()
        baseReqVo.appInfo = ReqAppInfoVo()
        baseReqVo.operation = API.OPERATION.QUERYBOOKINFO
        baseReqVo.requestObject = API.PARAM.PARAGM_ACS_REQUEST_OBJECT
        var queryBookReq = QueryBookReq()
        queryBookReq.BookSn = bookSn
        queryBookReq.LibraryCode = AppConstant.getLibraryCode()
        queryBookReq.Mac =AppConstant.getMachineUuid()
        baseReqVo.data = queryBookReq
        return baseReqVo
    }
    fun getFaceReqData():BaseReqVo<FaceSynReq>{
        // 0为全量，非0为增量
        var lastResourceBundleRecordId = AppConstant.getLastFaceResRecordId()
        var faceReq = BaseReqVo<FaceSynReq>()
        var faceSynReq = FaceSynReq(AppConstant.getFaceLibraryCode(),
            lastResourceBundleRecordId,AppConstant.getLibraryCode())
        faceReq.data = faceSynReq
        faceReq.appInfo = ReqAppInfoVo()
        faceReq.description = ""
        faceReq.operation = API.OPERATION.PULLINCNPACKAGE
        faceReq.requestObject = API.PARAM.PARAGM_REQUEST_OBJECT_FACE
        return faceReq
    }

    fun getFaceTokenReqData(): AccessTokenReq {
        var accessTokenReq = AccessTokenReq(AppConstant.getLibraryCode(),
            AppConstant.getFaceTokenAccount(),AppConstant.getFacePassword())
        return accessTokenReq
    }

    fun getBorrowBookReqData(bookSn:String,patronSn:String):BaseReqVo<QueryBookReq>{
        var baseReqVo = BaseReqVo<QueryBookReq>()
        baseReqVo.appInfo = ReqAppInfoVo()
        baseReqVo.operation = API.OPERATION.LENDBOOK
        baseReqVo.requestObject = API.PARAM.PARAGM_ACS_REQUEST_OBJECT
        var queryBookReq = QueryBookReq()
        queryBookReq.BookSn = bookSn
        queryBookReq.LibraryCode = AppConstant.getLibraryCode()
        queryBookReq.Mac = AppConstant.getMachineUuid()
        queryBookReq.PatronSn = patronSn
        baseReqVo.data = queryBookReq
//        LogUtils.d("net ${deviceBookDto.number} 借书信息：${baseReqVo}")
        return baseReqVo
    }
    fun getRetunBookReqData(bookSn: String,patronSn:String):BaseReqVo<QueryBookReq>{
        var baseReqVo = BaseReqVo<QueryBookReq>()
        baseReqVo.appInfo = ReqAppInfoVo()
        baseReqVo.operation = API.OPERATION.RETURNBOOK
        baseReqVo.requestObject = API.PARAM.PARAGM_ACS_REQUEST_OBJECT
        var queryBookReq = QueryBookReq()
        queryBookReq.BookSn = bookSn
        queryBookReq.LibraryCode = AppConstant.getLibraryCode()
        queryBookReq.Mac = AppConstant.getMachineUuid()
        queryBookReq.PatronSn = patronSn
        baseReqVo.data = queryBookReq
        return baseReqVo
    }

    fun getRennewBookReqData(bookSn: String?,patronSn:String):BaseReqVo<QueryBookReq>{
        var baseReqVo = BaseReqVo<QueryBookReq>()
        baseReqVo.appInfo = ReqAppInfoVo()
        baseReqVo.operation = API.OPERATION.RENEWBOOK
        baseReqVo.requestObject = API.PARAM.PARAGM_ACS_REQUEST_OBJECT
        var queryBookReq = QueryBookReq()
        queryBookReq.BookSn = bookSn
        queryBookReq.LibraryCode = AppConstant.getLibraryCode()
        queryBookReq.Mac = AppConstant.getMachineUuid()
        queryBookReq.PatronSn = patronSn
        baseReqVo.data = queryBookReq
        return baseReqVo
    }
}